var { getLoginedUser, fnLoading, fnHideLoading, fnSuccess, fnFail } = require('../../utils/index')
import { domainStatic } from '../../utils/env.js';
import _ from '../../utils/underscore.js';
import { get, fnChoose, lsGetStr, lsGetObj,lsSetStr,fnUpload, post } from '../../utils/request.js';
// pages/popularize/index.js
var app = getApp
Page({
  /**
   * 页面的初始数据
   */
  data: {
    headimgurl: "",
    id: "",
    
  },
  downloadImg:function(){
    wx.navigateTo({
      url: '../participate/index',
    })
  },
  add_address_fun: function () {
    wx.navigateTo({
      url: 'add_address/add_address',
    })
  },
  onLoad: function () {
    var that = this;
    /**
     * 获取用户信息
     */
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) { 
    let number = lsGetObj('loginedUser').id||'103'
    
    this.setData({
      number: number 
    })
     
    let that=this;
    fnLoading('加载中...')
    if (options.id){
      get({
        path: '/user/get?id=' + options.id
      })
    .then(res=>{
        //console.log(res);
      fnHideLoading();
        //
      that.setData({
        user: res
      })
    })
    }else{
      fnHideLoading();
      that.setData({ user:{
        id: options.id,
        nickName:'合伙人',
        headimgurl: options.headimgurl
      }
      })
    }
    wx.getUserInfo({
      success: function (res) {
        console.log(res);
        var headImg = 'userInfo.headImg';
        var nickName = 'userInfo.nickName';
        that.setData({
          [headImg]: res.userInfo.avatarUrl,
          [nickName]: res.userInfo.nickName,
        });
      }
    })
    
  }, 
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let that = this;    
    return {
      title: '闻权我们做软著不收费，政府项目免费给您先报。', // 转发后 所显示的title
      path: '/pages/home2/index?partnerId=' + lsGetObj('loginedUser').id,// 相对的路径
      imageUrl:'http://www.taicanglimi.cn/admin/imgs/min/share.png',
      success: (res) => {    // 成功后要做的事情
        wx.getShareInfo({
          shareTicket: res.shareTickets[0],
          success: (res) => {
            that.setData({
              isShow: true
            })
          },
          fail: function (res) { console.log(res) },
          complete: function (res) { console.log(res) }
        })
      },
      fail: function (res) {
        // 分享失败
        console.log(res)
      }
    }
  }
})